package com.luocj.looook.fragment;

import android.os.Environment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.AppCompatEditText;
import android.util.Log;

import com.luocj.looook.R;
import com.luocj.looook.base.BaseFragment;
import com.luocj.looook.utils.GlideImageLoader;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;

import java.util.ArrayList;

/**
 * Created by luocj515 on 2017/11/30.
 * 项目名称：LooooK
 * 类描述：
 * 创建人：hasee
 * 创建时间：2017/11/30 13:41
 * 修改备注：
 */

public class TEST1Fragment extends BaseFragment {

    private static final String TAG = TEST1Fragment.class.getSimpleName();
    private ArrayList<Integer> images;
    private ArrayList<String> urls;
    private ArrayList<String> titles;
    private Banner banner1;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_test1;
    }

    @Override
    protected void initData() {

        titles = new ArrayList<>();
        titles.add("title0 -------->");
        titles.add("title1 -------->");
        titles.add("title2 -------->");
        titles.add("title3 -------->");
        titles.add("title4 -------->");


        images = new ArrayList<>();
        images.add(R.mipmap.b1);
        images.add(R.mipmap.b2);
        images.add(R.mipmap.b3);

        urls = new ArrayList<>();
        urls.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic1xjab4j30ci08cjrv.jpg");
        urls.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic21363tj30ci08ct96.jpg");
        urls.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic259ohaj30ci08c74r.jpg");
        urls.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic2b16zuj30ci08cwf4.jpg");
        urls.add("http://ww4.sinaimg.cn/large/006uZZy8jw1faic2e7vsaj30ci08cglz.jpg");

    }

    @Override
    protected void initView() {
        final AppCompatEditText editText = mContentView.findViewById(R.id.acet_password);
        Banner banner = mContentView.findViewById(R.id.banner);
        banner1 = mContentView.findViewById(R.id.banner1);

        banner1.setImages(urls)
                .setBannerTitles(titles)
                .setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE)
                .setImageLoader(new GlideImageLoader())
                .start();

        banner1.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                Log.i(TAG, "onPageSelected: " + position);
                String externalStorageDirectory = Environment.getExternalStorageDirectory().getPath();
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });


        banner.setImages(images)
                .setImageLoader(new GlideImageLoader())
                .start();
    }

    //如果你需要考虑更好的体验，可以这么操作
    @Override
    public void onStart() {
        super.onStart();
        //开始轮播
        banner1.startAutoPlay();
    }

    @Override
    public void onStop() {
        super.onStop();
        //结束轮播
        banner1.stopAutoPlay();
    }
}
